package dao.impl;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import dao.rejectListNumberForPageInterface;

public class rejectListNumberForPage implements Serializable, rejectListNumberForPageInterface{
 
@SuppressWarnings({ "null", "unchecked" })
public List  getRow(String TypeClassName,int currentPage,int singlePageRow,String usefunctionName){
	 		List listTemp=new ArrayList(); 
			ListNumbersForPage listNumbersForPage = new ListNumbersForPage();
			listNumbersForPage.setType(TypeClassName);
			listNumbersForPage.setCurrentPage(currentPage);
			listNumbersForPage.setSinglePageRow(singlePageRow);
			List  listTest = new ArrayList();
			if (listNumbersForPage.list() != null) { 
				listTest = listNumbersForPage.list();
//				System.out.println("in  test the size is:::;"+listTest.size());
				Iterator iter = listTest.iterator();
				 
				while (iter.hasNext()) {
					try { 
						Class ClassTemp = Class.forName(listNumbersForPage.getType());
						Object object=ClassTemp.newInstance();
						object= iter.next(); 
						Method methodTemp=ClassTemp.getMethod(usefunctionName,new Class[]{}); 
						int Id=(Integer) methodTemp.invoke(object,new Object[]{}); 
						 listTemp.add(Id); 
						
						
						

					} catch (SecurityException e) {
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						e.printStackTrace();
//					} catch (NoSuchMethodException e) {
//						e.printStackTrace();
					} catch (NoSuchMethodException e) { 
						e.printStackTrace();
					} catch (IllegalArgumentException e) { 
						e.printStackTrace();
					} catch (IllegalAccessException e) { 
						e.printStackTrace();
					} catch (InvocationTargetException e) { 
						e.printStackTrace();
					} catch (InstantiationException e) { 
						e.printStackTrace();
					}

				}
				return listTemp;
			}
			return null;
		}
@SuppressWarnings({ "null", "unchecked" })
public List  getRowHasCondition(String TypeClassName,int currentPage,int singlePageRow,String usefunctionName,String ConditionTemp){
	 		List listTemp=new ArrayList(); 
			ListNumbersForPage listNumbersForPage = new ListNumbersForPage();
			listNumbersForPage.setType(TypeClassName);
			listNumbersForPage.setCurrentPage(currentPage);
			listNumbersForPage.setSinglePageRow(singlePageRow);
			listNumbersForPage.setCondition(ConditionTemp);
			List  listTest = new ArrayList();
			if (listNumbersForPage.list() != null) { 
				listTest = listNumbersForPage.list();
//				System.out.println("in  test the size is:::;"+listTest.size());
				Iterator iter = listTest.iterator();
				 
				while (iter.hasNext()) {
					try { 
						Class ClassTemp = Class.forName(listNumbersForPage.getType());
						Object object=ClassTemp.newInstance();
						object= iter.next(); 
						Method methodTemp=ClassTemp.getMethod(usefunctionName,new Class[]{}); 
						int Id=(Integer) methodTemp.invoke(object,new Object[]{}); 
						 listTemp.add(Id); 
						
						
						

					} catch (SecurityException e) {
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						e.printStackTrace();
//					} catch (NoSuchMethodException e) {
//						e.printStackTrace();
					} catch (NoSuchMethodException e) { 
						e.printStackTrace();
					} catch (IllegalArgumentException e) { 
						e.printStackTrace();
					} catch (IllegalAccessException e) { 
						e.printStackTrace();
					} catch (InvocationTargetException e) { 
						e.printStackTrace();
					} catch (InstantiationException e) { 
						e.printStackTrace();
					}

				}
				return listTemp;
			}
			return null;
		}
@SuppressWarnings({ "null", "unchecked" })
public List  getRowReverse(String TypeClassName,int currentPage,int singlePageRow,String usefunctionName,String ConditionTemp){
	 		List listTemp=new ArrayList(); 
			ListNumbersForPage listNumbersForPage = new ListNumbersForPage();
			listNumbersForPage.setType(TypeClassName);
			listNumbersForPage.setCurrentPage(currentPage);
			listNumbersForPage.setSinglePageRow(singlePageRow);
			listNumbersForPage.setCondition(ConditionTemp);
			List  listTest = new ArrayList();
			if (listNumbersForPage.list() != null) { 
				listTest = listNumbersForPage.listReverse();
//				System.out.println("in  test the size is:::;"+listTest.size());
				Iterator iter = listTest.iterator();
				 
				while (iter.hasNext()) {
					try { 
						Class ClassTemp = Class.forName(listNumbersForPage.getType());
						Object object=ClassTemp.newInstance();
						object= iter.next(); 
						Method methodTemp=ClassTemp.getMethod(usefunctionName,new Class[]{}); 
						int Id=(Integer) methodTemp.invoke(object,new Object[]{}); 
						 listTemp.add(Id); 
						
						
						

					} catch (SecurityException e) {
						e.printStackTrace();
					} catch (ClassNotFoundException e) {
						e.printStackTrace();
//					} catch (NoSuchMethodException e) {
//						e.printStackTrace();
					} catch (NoSuchMethodException e) { 
						e.printStackTrace();
					} catch (IllegalArgumentException e) { 
						e.printStackTrace();
					} catch (IllegalAccessException e) { 
						e.printStackTrace();
					} catch (InvocationTargetException e) { 
						e.printStackTrace();
					} catch (InstantiationException e) { 
						e.printStackTrace();
					}

				}
				return listTemp;
			}
			return null;
		}

 }

